import time

from appium.webdriver.common.mobileby import MobileBy


class FinanceOperation:
  def finance(self, driver):
    # 点击同意按钮
    driver.find_element(MobileBy.ID, "com.duxiaoman.wallet:id/protocol_dialog_pos_btn").click()
    time.sleep(5)
    # 点击拒绝按钮
    driver.find_element(MobileBy.XPATH,
                              "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.Button[1]").click()
    time.sleep(5)

    driver.find_element(MobileBy.ACCESSIBILITY_ID, '理财').click()
    time.sleep(5)
    # 选择理财产品
    driver.find_element(MobileBy.XPATH, "//android.widget.TextView[@text='货币基金']").click()
    time.sleep(5)
    # 填写相关信息并提交
    driver.find_element(MobileBy.ID, "com.baidu.wallet:id/et_amount").send_keys('1000')
    time.sleep(5)
    driver.find_element(MobileBy.ID, "com.baidu.wallet:id/btn_submit").click()
    time.sleep(5)
    # 获取提示信息
    result = driver.find_element(MobileBy.ID, "com.baidu.wallet:id/information").text
    time.sleep(5)
    if result == '购买成功！':
        return 1
    else:
        return 0
